﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;


public partial class _Default : System.Web.UI.Page
{
    int id= 0;
    string ClassID = "";
    string CourseID = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["Student"] == null)
                Response.Redirect("~/Student/HomePage.aspx");
            id = Convert.ToInt32(Request.QueryString["id"].ToString());

            string strConn = "SELECT Competition.Competition_Name, Competition.Competition_Detail, Competition.Start_Date, Competition.End_Date, Staff.Firstname+' '+Staff.Lastname AS FullName, Class.ClassID, Course.Course_Name, Course.CourseID";
            strConn += " FROM Course INNER JOIN";
            strConn += " Competition ON Course.CourseID = Competition.CourseID INNER JOIN";
            strConn += " Class ON Competition.ClassID = Class.ClassID INNER JOIN";
            strConn += " Staff ON Competition.StaffID = Staff.StaffID";
            strConn += " WHERE CompetitionID ='" + id + "'";            

            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Institte_of_Fine_ArtsConnectionString"].ConnectionString);
            conn.Open();
            SqlCommand comm = new SqlCommand();
            comm.CommandText = strConn;
            comm.CommandType = CommandType.Text;
            comm.Connection = conn;
            SqlDataReader read = comm.ExecuteReader();
            while (read.Read())
            {
                lbTitle.Text = read.GetString(0);                
                memoCompetition_Details.Text = read.GetString(1);
                lbStartDate.Text = read.GetDateTime(2).ToString();
                lbEndDate.Text = read.GetDateTime(3).ToString(); ;
                lbStaff.Text = read.GetString(4);
                ClassID = read.GetString(5);
                lbCourse.Text = read.GetString(6);                
                CourseID = read.GetString(7);
                lbClass.Text = ClassID;                
            }
        }
        catch (Exception ex)
        {
            if (id == 0)
            {
                lbStattusCompetitionDetail.Text = "Error: You don't select competition! Please back!";
            }
            else
            {
                Response.Write("Error: " + ex.Message);
            }            
        }
        
    }
    protected void btPosting_Click(object sender, EventArgs e)
    {        
        Response.Redirect("~/Student/Posting.aspx?id="+ id +"&ClassID="+ ClassID +"&CourseID="+ CourseID);
    }
}